/**
 The MIT License

Copyright (c) <2011> <JPACHUBE Team>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
 */
package com.pachube.commons.impl;

import com.pachube.api.Disposition;
import com.pachube.api.Domain;
import com.pachube.api.Exposure;
import com.pachube.api.Location;

/**
 * The Class LocationImpl.
 */
public class LocationImpl implements Location {

    /** The name. */
    private String name;

    /** The lat. */
    private double lat;

    /** The lon. */
    private double lon;

    /** The elevation. */
    private double elevation;

    /** The exposure. */
    private Exposure exposure;

    /** The domain. */
    private Domain domain;

    /** The disposition. */
    private Disposition disposition;

    /**
     * Instantiates a new location impl.
     */
    public LocationImpl() {
        // TODO Auto-generated constructor stub
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#setLat(java.lang.String)
     */
    public void setLat(String lat) {
        try {
            this.lat = Double.parseDouble(lat);
        } catch (Exception c) {
            this.lat = 0.0;
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#setLon(java.lang.String)
     */
    public void setLon(String lon) {
        try {
            this.lon = Double.parseDouble(lon);
        } catch (Exception c) {
            this.lon = 0.0;
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#setElevation(java.lang.String)
     */
    public void setElevation(String elevation) {
        try {
            this.elevation = Double.parseDouble(elevation);
        } catch (Exception c) {
            this.elevation = 0.0;
        }
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#toXML()
     */
    public String toXML() {
        String ret = "";
        ret = "<location ";

        if (this.domain != null) {
            ret = ret + "domain=\"" + this.domain + "\" ";
        }

        if (this.exposure != null) {
            ret = ret + "exposure=\"" + this.exposure + "\" ";
        }

        if (this.disposition != null) {
            ret = ret + "disposition=\"" + this.disposition + "\" ";
        }
        ret = ret + ">\n\t\t";
        ret = ret + "<name>" + this.name + "</name>\n\t\t";
        ret = ret + "<lat>" + this.lat + "</lat>\n\t\t";
        ret = ret + "<lon>" + this.lon + "</lon>\n\t\t";
        ret = ret + "<ele>" + this.elevation + "</ele>\n\t";
        ret = ret + "</location>";
        return ret;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#toString()
     */
    @Override
    public String toString() {
        return "Location [disposition=" + this.disposition + ", domain="
                + this.domain + ", elevation=" + this.elevation + ", exposure="
                + this.exposure + ", lat=" + this.lat + ", lon=" + this.lon
                + ", name=" + this.name + "]";
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#getName()
     */
    public String getName() {
        return this.name;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#setName(java.lang.String)
     */
    public void setName(String name) {
        this.name = name;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#getLat()
     */
    public double getLat() {
        return this.lat;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#setLat(double)
     */
    public void setLat(double lat) {
        this.lat = lat;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#getLon()
     */
    public double getLon() {
        return this.lon;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#setLon(double)
     */
    public void setLon(double lon) {
        this.lon = lon;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#getElevation()
     */
    public double getElevation() {
        return this.elevation;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#setElevation(double)
     */
    public void setElevation(double elevation) {
        this.elevation = elevation;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#getExposure()
     */
    public Exposure getExposure() {
        return this.exposure;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#setExposure(com.pachube.api.Exposure)
     */
    public void setExposure(Exposure exposure) {
        this.exposure = exposure;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#getDomain()
     */
    public Domain getDomain() {
        return this.domain;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#setDomain(com.pachube.api.Domain)
     */
    public void setDomain(Domain domain) {
        this.domain = domain;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#getDisposition()
     */
    public Disposition getDisposition() {
        return this.disposition;
    }

    /*
     * (non-Javadoc)
     * 
     * @see Pachube.Location#setDisposition(com.pachube.api.Disposition)
     */
    public void setDisposition(Disposition disposition) {
        this.disposition = disposition;
    }

}
